import java.util.Scanner;

public class Demo4 {
    public static int flag = 0;
    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            while (flag == 0) {//内存可见性
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println(Thread.currentThread().getName());
        });

        Thread thread2 = new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            flag = scanner.nextInt();
        });

        thread1.start();
        thread2.start();
    }
}
